﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Ui;

namespace Rj_GsInsurance.Client.Controls
{
    public class GalleryNavigationPresenter : Control
    {
        /// <summary>
        /// Property for <see cref="ItemsSource"/>.
        /// </summary>
        public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
            nameof(ItemsSource),
            typeof(object),
            typeof(GalleryNavigationPresenter),
            new PropertyMetadata(null)
        );

        /// <summary>
        /// Property for <see cref="TemplateButtonCommand"/>.
        /// </summary>
        public static readonly DependencyProperty TemplateButtonCommandProperty = DependencyProperty.Register(
            nameof(TemplateButtonCommand),
            typeof(Wpf.Ui.Input.IRelayCommand),
            typeof(GalleryNavigationPresenter),
            new PropertyMetadata(null)
        );

        public object? ItemsSource
        {
            get => GetValue(ItemsSourceProperty);
            set => SetValue(ItemsSourceProperty, value);
        }

        /// <summary>
        /// Gets the command triggered after clicking the titlebar button.
        /// </summary>
        public Wpf.Ui.Input.IRelayCommand TemplateButtonCommand =>
            (Wpf.Ui.Input.IRelayCommand)GetValue(TemplateButtonCommandProperty);

        /// <summary>
        /// Initializes a new instance of the <see cref="GalleryNavigationPresenter"/> class.
        /// Creates a new instance of the class and sets the default <see cref="FrameworkElement.Loaded"/> event.
        /// </summary>
        public GalleryNavigationPresenter()
        {
            SetValue(TemplateButtonCommandProperty, new Wpf.Ui.Input.RelayCommand<Type>(o => OnTemplateButtonClick(o)));
        }

        private void OnTemplateButtonClick(Type? pageType)
        {
            INavigationService navigationService = App.GetRequiredService<INavigationService>();

            if (pageType is not null)
            {
                navigationService.Navigate(pageType);
            }
        }
    }
}
